package com.example.certificate.controller;

import com.example.certificate.annoatiton.CurrentUser;
import com.example.certificate.annoatiton.LoginToken;
import com.example.certificate.dto.CorporateBringDto;
import com.example.certificate.dto.QueryActivityPageDTO;
import com.example.certificate.entity.SysActivite;
import com.example.certificate.entity.User;
import com.example.certificate.service.SysActiviteService;
import com.example.certificate.utils.ResultEntity;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.ir.annotations.Ignore;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;

/**
 * <p>
 *  前端控制器
 * </p>
 */
@RestController
@RequestMapping("/certificate/sysActivite")
public class SysActiviteController {

    @Resource
    private SysActiviteService sysActiviteService;


    @LoginToken
    @ApiOperation(value = "新增活动")
    @PostMapping(value = "/insActivity")
    ResultEntity insActivity(@RequestBody SysActivite model, @Ignore @CurrentUser User user) throws ParseException {
        return sysActiviteService.insActivity(model, user);
    }


    @LoginToken
    @ApiOperation(value = "删除活动")
    @PostMapping(value = "/delActivity")
    ResultEntity delActivity(@RequestBody CorporateBringDto model) {
        return sysActiviteService.delActivity(model.getId());
    }


    @LoginToken
    @ApiOperation(value = "编辑活动")
    @PostMapping(value = "/editActivity")
    ResultEntity editActivity(@RequestBody SysActivite model) {
        return sysActiviteService.editActivity(model);
    }


    @ApiOperation(value = "搜索活动列表")
    @GetMapping(value = "/queryActivity")
    ResultEntity queryActivity() {
        return sysActiviteService.queryActivity();
    }


    @ApiOperation(value = "搜索活动分页")
    @PostMapping(value = "/queryActivityPage")
    ResultEntity queryActivityPage(@RequestBody QueryActivityPageDTO model){
        return sysActiviteService.queryActivityPage(model.getName(), model.getCurrentPage(), model.getPageSize());
    }
}
